--[[
Author: gotpldapco
Date: 2022-09-09 09:16:17
LastEditors: gotpl
LastEditTime: 2022-09-09 11:25:15
FilePath: /nvim-config/lua/plugin-config/dap/init.lua
--]]
--[[
Author: gotpl
Date: 2022-09-09 09:16:17
LastEditors: gotpl
LastEditTime: 2022-09-09 11:21:26
FilePath: /nvim-config/lua/dap/init.lua
--]]
local M = {}


local function configure()
    -- local dap_install = require "dap-install"
    -- dap_install.setup {
    --   installation_path = vim.fn.stdpath "data" .. "/dapinstall/",
    -- }


    vim.api.nvim_set_hl(0, 'DapBreakpoint', { ctermbg=0, fg='#993939', bg='#31353f' })
    vim.api.nvim_set_hl(0, 'DapLogPoint', { ctermbg=0, fg='#61afef', bg='#31353f' })
    vim.api.nvim_set_hl(0, 'DapStopped', { ctermbg=0, fg='#98c379', bg='#31353f' })
    vim.fn.sign_define('DapBreakpoint', { text='', texthl='DapBreakpoint', linehl='DapBreakpoint', numhl='DapBreakpoint' })
    vim.fn.sign_define('DapBreakpointCondition', { text='', texthl='DapBreakpoint', linehl='DapBreakpoint', numhl='DapBreakpoint' })
    vim.fn.sign_define('DapBreakpointRejected', { text='', texthl='DapBreakpoint', linehl='DapBreakpoint', numhl= 'DapBreakpoint' })
    vim.fn.sign_define('DapLogPoint', { text='', texthl='DapLogPoint', linehl='DapLogPoint', numhl= 'DapLogPoint' })
    vim.fn.sign_define('DapStopped', { text='', texthl='DapStopped', linehl='DapStopped', numhl= 'DapStopped' })

    --local dap_breakpoint = {
        --error = {
            --text = "",
            --texthl = "DapBreakpoint",
            --linehl = "",
            --numhl = "",
        --},
        --rejected = {
            --text = "",
            --texthl = "LspDiagnosticsSignHint",
            --linehl = "",
            --numhl = "",
        --},
        --stopped = {
            --text = "⭐️",
            --texthl = "LspDiagnosticsSignInformation",
            --linehl = "DiagnosticUnderlineInfo",
            --numhl = "LspDiagnosticsSignInformation",
        --},
    --}

    --vim.fn.sign_define("DapBreakpoint", dap_breakpoint.error)
    --vim.fn.sign_define("DapStopped", dap_breakpoint.stopped)
    --vim.fn.sign_define("DapBreakpointRejected", dap_breakpoint.rejected)
end

local function configure_exts()
    require("nvim-dap-virtual-text").setup {
        commented = true,
    }
    local dap, dapui = require "dap", require "dapui"
    dapui.setup()
    dap.set_log_level("DEBUG")
    --dap.listeners.after.event_initialized[""]
    --dapui.setup {} -- use default
            --print(vim.inspect(dap.listeners.after.event_initialized))
        --require("dap.ext.vscode").load_launchjs(nil, { cppdbg = { "c", "cpp" } })
    --end
    dap.listeners.after.event_initialized["dapui_config"] = function()
        dapui.open()
        vim.api.nvim_command("DapVirtualTextEnable")
    end
    dap.listeners.before.event_terminated["dapui_config"] = function()
        --dapui.close()
        vim.api.nvim_command("DapVirtualTextDisable")
    end
    dap.listeners.before.event_exited["dapui_config"] = function()
        --dapui.close()
        vim.api.nvim_command("DapVirtualTextDisable")
    end
    dap.defaults.fallback.terminal_win_cmd = "vsplit new"
end

local function configure_debuggers()
    -- require('dap.ext.vscode').json_decode = require'json5'.parse
    --require("dap.ext.vscode").load_launchjs(nil, { cppdbg = { "c", "cpp" } })
    require("plugin-config.dap.lua")
    require("plugin-config.dap.python")
    require("plugin-config.dap.c")
    --require("plugin-config.dap.lua").setup()
    --require("plugin-config.dap.python").setup()
    --require("plugin-config.dap.c").setup()
end

function M.setup()
    --require("dap.ext.vscode").load_launchjs(nil, { cppdbg = { "c", "cpp" } })
    configure() -- Configuration
    configure_exts() -- Extensions
    configure_debuggers() -- Debugger
    require("plugin-config.dap.keymaps").setup() -- Keymaps
end

--configure_debuggers()
--M.setup()
return M
